package asia.yuanding.wechat.web.netty.manager;

import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName: GroupManager
 * @Author: YuanDing
 * @Date: 2025/8/3 21:35
 * @Description:
 */

public class GroupManager {
    // groupId -> Set<userId>
    private static final Map<String, Set<String>> groupMap = new ConcurrentHashMap<>();

    public static void addUserToGroup(String groupId, String userId) {
        groupMap.computeIfAbsent(groupId, k -> ConcurrentHashMap.newKeySet()).add(userId);
    }

    public static void removeUserFromGroup(String groupId, String userId) {
        Set<String> members = groupMap.get(groupId);
        if (members != null) members.remove(userId);
    }

    public static Set<String> getGroupMembers(String groupId) {
        return groupMap.getOrDefault(groupId, Collections.emptySet());
    }
}
